package com.newbingo.action;

import java.util.List;

import com.googlecode.jsonplugin.annotations.JSON;
import com.newbingo.entity.Game;
import com.opensymphony.xwork2.ActionSupport;
import com.newbingo.service.imple.IGameService;
import com.newbingo.util.*;

public class GameAction extends ActionSupport {
	private Pager pager = null;
	private IGameService gameService = null;
	private Game game;
	private List gameDtos;
	/* 分页条件 */
	private int start;
	private int limit = 20;
	/* 查询条件 */
	private String type;

	/*
	 * 判断方法执行是否正确
	 * 
	 * 每个action都需要，页面会获得这个信息来提示用户返回时候正确
	 */
	private Boolean success = false;

	/*
	 * 查询所有的游戏，输出游戏桌，显示出在页面上，供会员选择
	 */
	public String findGameDtos() {
		gameDtos=gameService.findAllDto();
		success=true;
		return SUCCESS;
	}

	/*
	 * 新增游戏
	 */
	public String create() {
		gameService.createGame(this.getGame());
		this.setGame(null);
		success = true;
		return SUCCESS;

	}

	/*
	 * 删除方法
	 */
	public String deleteGame() {
		if (game != null) {
			gameService.delete(game);

		} else {
			success = false;
		}
		success = true;

		return SUCCESS;

	}

	/*
	 * 修改
	 */
	public String updateGame() {
		Game new_game = gameService.findById(game.getGameno());
		if (game == null) {
			success = false;
		} else {
			new_game.setGamename(game.getGamename());
			new_game.setType(game.getType());
			new_game.setRule(game.getRule());
			gameService.updateGame(new_game);
			success = true;
		}
		return SUCCESS;

	}

	/*
	 * 查询游戏 @param type 游戏类型
	 */
	public String findByPage() {
		this.setPager(gameService.findByPage(start, limit, type));
		return SUCCESS;
	}

	/*
	 * 根据编号查询
	 */
	public String findById() {
		this.setGame(gameService.findById(game.getGameno()));
		// return SUCCESS;
		return "find";
	}

	public Boolean getSuccess() {
		return success;
	}

	public void setSuccess(Boolean success) {
		this.success = success;
	}

	// @JSON(name = "games")
	public Pager getPager() {
		return pager;
	}

	public void setPager(Pager pager) {
		this.pager = pager;
	}

	@JSON(serialize = false)
	public IGameService getGameService() {
		return gameService;
	}

	public void setGameService(IGameService gameService) {
		this.gameService = gameService;
	}

	public Game getGame() {
		return game;
	}

	public void setGame(Game game) {
		this.game = game;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public List getGameDtos() {
		return gameDtos;
	}

	public void setGameDtos(List gameDtos) {
		this.gameDtos = gameDtos;
	}

}
